Skip to content

Added Validator to WarpSyncProvider#10223

Merged
bkchr merged 15 commits intoparitytech:masterfrom
input-output-hk:context_for_warp_sync_provider
Dec 15, 2025
Merged

Added Validator to WarpSyncProvider#10223
bkchr merged 15 commits intoparitytech:masterfrom
input-output-hk:context_for_warp_sync_provider

Conversation

@Klapeyron
Copy link
Copy Markdown
Contributor

@Klapeyron Klapeyron commented Nov 6, 2025

Description

It looks like WarpSyncProvider in sc-network-sync has direct dependency to sp-consensus-gradnpa types, specially SetId and AuthorityList:

/// Warp sync backend. Handles retrieving and verifying warp sync proofs.
pub trait WarpSyncProvider<Block: BlockT>: Send + Sync {
	/// Generate proof starting at given block hash. The proof is accumulated until maximum proof
	/// size is reached.
	fn generate(
		&self,
		start: Block::Hash,
	) -> Result<EncodedProof, Box<dyn std::error::Error + Send + Sync>>;
	/// Verify warp proof against current set of authorities.
	fn verify(
		&self,
		proof: &EncodedProof,
		set_id: SetId,
		authorities: AuthorityList,
	) -> Result<VerificationResult<Block>, Box<dyn std::error::Error + Send + Sync>>;
	/// Get current list of authorities. This is supposed to be genesis authorities when starting
	/// sync.
	fn current_authorities(&self) -> AuthorityList;
}

This PR is removing this dependency and replaces it with Validator, which can be used to validate proofs.

@Klapeyron Klapeyron force-pushed the context_for_warp_sync_provider branch from d3b5b26 to 2ef715e Compare November 7, 2025 16:41
Copy link
Copy Markdown
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the pull request!

Sorry for the delay until you got this review. See my comment on what needs to be changed. The general idea of the pull request is fine, but the implementation needs to be changed a little bit.

}

/// Warp sync backend. Handles retrieving and verifying warp sync proofs.
pub trait WarpSyncProvider<Block: BlockT>: Send + Sync {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not introduce the Context type. This requires too many changes that are not really required.

I think we should change the WarpSyncProvider trait in the following way:

  • Remove verify and current_context.
  • Introduce a new create_verifier() -> Arc<Verifier> (maybe you come up with a better name).
trait Verifier<Block> {
      fn verify(proof) -> Result;
      /// Returns the context in which the verifier operates
      fn context() -> Block::Hash;
}
  • context() for now will always return the genesis hash.
  • last_hash can then replaced with calls to context().

This way we don't require the pass through of the generic parameter to everywhere and also prepare the trait for the future.

@Klapeyron Klapeyron force-pushed the context_for_warp_sync_provider branch from efba492 to 7d5cc5c Compare December 4, 2025 18:48
@Klapeyron Klapeyron changed the title Added WarpSyncContext for WarpSyncProvider Added Validator to WarpSyncProvider Dec 4, 2025
pub struct WarpSync<B: BlockT, Client> {
phase: Phase<B>,
client: Arc<Client>,
_client: Arc<Client>,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after lates changes, this client is only used in new function, but I left it to not adjust the interfaces elsewhere. Please let me know if we want to provide some phantom here, remove it or leave or something else

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove it. We still need client in new. So, we don't need to change any interfaces, but we don't need to store it here.

@Klapeyron
Copy link
Copy Markdown
Contributor Author

Thank you @bkchr! It simplified this code significantly, I will appreciate if you will allocate some time to make a second round of review, meanwhile I will prepare some prdoc.

.ok_or_else(|| "Empty proof".to_string())?;
let (next_set_id, next_authorities) =
proof.verify(set_id, authorities, &self.hard_forks).map_err(Box::new)?;
let (_next_set_id, _next_authorities) = proof
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is a interior mutability case that is still not solved, I will take a look later

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also curious how the CI tests passed, looks like none of the tests is rotating committee?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah probably missing tests.

Copy link
Copy Markdown
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some last nitpicks, otherwise looks good!

pub struct WarpSync<B: BlockT, Client> {
phase: Phase<B>,
client: Arc<Client>,
_client: Arc<Client>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove it. We still need client in new. So, we don't need to change any interfaces, but we don't need to store it here.

*authorities = new_authorities;
Ok(VerificationResult::Partial(new_last_hash, proofs)) => {
debug!(target: LOG_TARGET, "Verified partial proof");
*last_hash = new_last_hash;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just remove last_hash completely and let verifier.context always return the latest hash. Maybe let's rename context to something like next_proof_context or something along these lines.

@bkchr bkchr added the T0-node This PR/Issue is related to the topic “node”. label Dec 8, 2025
})
.collect::<Vec<_>>();
{
let mut state = self.state.lock();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state might become inconsistent, since there's a possibly large gap between the acquired locks. Is this a scenario that can happen within our code?

-T0: [thread 0] first .lock
-T1: [thread 1] first .lock
-T2: [thread 1] complets verifying and sets [next_auth 1, last_header 1]
-T3: [thread 0] complets verifying but now we are overwritting the sets set at T2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6e35423
Thank you, I made it scoped. My first thought was that this process is synchronous by default, introduction of Mutex/RefCell is for immutability

Copy link
Copy Markdown
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah last change and then we can merge this.

proof.verify(set_id, authorities, &self.hard_forks).map_err(Box::new)?;

{
let mut state = self.state.lock();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just let's make verify take &mut self. We don't really need the mutex here.

@bkchr
Copy link
Copy Markdown
Member

bkchr commented Dec 12, 2025

Please also merge master, there are some fixes for some of the flaky CI jobs.

@bkchr bkchr requested a review from lexnv December 12, 2025 08:08
@bkchr bkchr mentioned this pull request Dec 12, 2025
3 tasks
@Klapeyron
Copy link
Copy Markdown
Contributor Author

Thank you. @bkchr if you could also take a look on this one: #10223 (comment), looks like there is some missing test for warp with rotating committee, due at the moment when this comment was created, validator was not persisting new authority set and CI was green. Maybe it can be addressed in some follow-up issue

@bkchr bkchr enabled auto-merge December 15, 2025 10:00
Copy link
Copy Markdown
Contributor

@lexnv lexnv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for contributing 🙏

@bkchr bkchr added this pull request to the merge queue Dec 15, 2025
Merged via the queue into paritytech:master with commit 310625d Dec 15, 2025
252 of 258 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T0-node This PR/Issue is related to the topic “node”.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants